﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WISD.CarFriend.Model;
using WISD.Common;
using WISD.CarFriend.BLL;
using WISD.CarFriend.BLL.Web;

namespace WISD.CarFriend.Web.Admin.Module.InformationManage
{
    public partial class Edit : Utility.BasicPage
    {
        #region 字段
        private int info_ID;
        #endregion


        #region 事件
        /// <summary>
        /// Page_Load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] == null || !int.TryParse(Request.QueryString["id"], out info_ID))
            {
                base.ShowMessageBox(350, 230, "错误提示", "<b>出现错误啦！</b>您要修改的信息不存在或参数不正确。", "back", "Error");
                return;
            }

            if (!IsPostBack)
            {
                // 验证权限
                base.CheckPermission("InformationManage_Edit");

                ddl_type.DataSource = TypeManageModule.GetAllType();
                ddl_type.DataTextField = "TypeName";
                ddl_type.DataValueField = "TypeID";
                ddl_type.DataBind();

                T_CF_Web_Information info = new T_CF_Web_Information();
                info = InformationManageModule.GetInfoByID(info_ID);
                if (info != null)
                {
                    txtTitle.Text = info.Title;
                    ddl_type.SelectedValue = info.TypeID.ToString();
                    cb_Istop.Checked = info.IsTop ?? false;
                    FCKeditor.Value = info.InfoContent;
                }
                else
                {
                    base.ShowMessageBox(350, 230, "错误提示", "<b>出现错误啦！</b>您要修改的信息不存在或参数不正确。", "back", "Error");
                }
            }
        }


        /// <summary>
        /// 修改资讯
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                T_CF_Web_Information MyInfo = new T_CF_Web_Information();
                MyInfo.InformationID = info_ID;
                MyInfo.Title = txtTitle.Text.Trim();
                MyInfo.TypeID = int.Parse(ddl_type.SelectedValue);
                MyInfo.IsTop = cb_Istop.Checked;
                MyInfo.InfoContent = FCKeditor.Value;
                MyInfo.UpdaterID = Session["UserID"].ToInt();
                InformationManageModule.UpdateNewInfo(MyInfo);
                ShowMessageBox("资讯修改成功！", "List.aspx", "Success");
            }
            catch (Exception ex)
            {
                base.ShowMessageBox(350, 230, "错误提示", "<b>出现错误啦！</b>" + ex.Message.ToString(), "back", "Error");
            }
        }
        #endregion

    }
}